<template>
    <div>
        <el-card style="width:50%">
            <el-form :model="form" label-width="80px" style="padding-right:30px">
                <el-form-item label="理念标题" prop="title">
                    <el-input v-model="form.title" id="title"></el-input>
                </el-form-item>

                <el-form-item label="理念内容" prop="word" >
                    <el-input type="textarea"  v-model="form.word" id="word"></el-input>
                </el-form-item>
                <el-form-item label="理念图片">
                    <el-upload
                        class="avatar-uploader"
                        action="http://localhost:9090/file/upload"
                        :headers="{ token: user.token }"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                        >
                        <img v-if="form.picture" :src="form.picture" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </el-form-item>
                <div style="text-align:center">
                    <el-button type="primary" @click="update">保存</el-button>
                </div>
            </el-form>
        </el-card>
    </div>
</template>

<script>
export default{
    name:"Idea",
    data(){
        return {
            form:{},
            user:JSON.parse(localStorage.getItem('honey-user') || '{}')
        }
    },
    created() {
        this.load(); // 在组件创建时调用 load() 方法
    },
    methods:{
        update(){
            this.$request.put('/content/update',this.form).then(res=>{
                if(res.code==='200'){
                    this.$message.success('保存成功')
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        handleAvatarSuccess(response,file,fileList){
            this.form.picture=response.data
        },
        load() {
        this.$request.get('/content/selectByPlate/理念').then(res => {
            this.form = res.data
        })
        },
    }
}
</script>

<style scoped>

.el-form-item__label{
    font-weight:bold;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border-radius: 50%;
}
.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader{
    display:inline-block
}
.avatar-uploader-icon {
    border: 1px dashed #d9d9d9;
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
.avatar {
    width: auto;
    height: 178px;
    display: block;
}
</style>